<!doctype HTML>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<title>湘小淋注册页面修改过程</title>
<style>
body {
color: #333;
font-family: sans-serif;
font-size: 12pt;
line-height: 170%;
padding: 0 30px 0 270px;
}

header .banner {
margin: 0 0 1em 0;
}

header .banner, nav .banner {
color: #777;
font-size: 10pt;
font-weight: bold;
}

header h1 {
background: #0c3;
border-radius: 4px;
color: #fff;
font-size: 24pt;
margin: 0;
padding: 1.2em 0;
text-align: center;
}

nav {
font-size: 10pt;
overflow-x: auto;
overflow-y: auto;
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 240px;
}

nav .menubar {
border-bottom: solid 1px #ccc;
display: none;
height: 48px;
line-height: 48px;
padding: 0 10px;
}

nav .button {
background: #777;
border: 1px solid #333;
color: #fff;
font-size: 10pt;
font-weight: bold;
padding: 8px;
border-radius: 4px;
}

nav ul {
padding: 0 0 0 10px;
}

nav ul a {
color: #333;
text-decoration: none;
}

nav ul a:hover {
text-decoration: underline;
}

nav li {
line-height: 180%;
list-style: none;
margin: 0;
padding: 0;
}

nav .level2 {
font-size: 11pt;
font-weight: bold;
}

nav .level3 {
padding-left: 1em;
}

nav .level3:before { 
content: "» ";
}

nav .level4 {
padding-left: 2em;
}

nav .level4:before {
content: "› ";
}

article h2 {
border-bottom: dotted 1px #777;
font-size: 20pt;
line-height: 100%;
margin: 2em 0 1em 0;
padding: 0 0 0.3em 0;
}

article h3 {
font-size: 12pt;
height:50px;
line-height: 50px;
margin: 2em 0 1em 0;
padding-left:20px;
background:#cccccc;
}

article h4 {
font-size: 12pt;
font-style:italic;
font-weight: normal;
line-height: 100%;
margin: 1.2em 0 1em 0;
padding: 0;
}

article p {
margin: 1em 0;
}

article p code {
background: #eee;
border: 1px solid #ccc;
}

article p strong {
color: #f00;
}

article pre {
background: #eee;
border-left: solid 2px #3c0;
font-size: 12px;
margin: 1em 0;
padding: 0 0 0 1em;
overflow-x: auto;
overflow-y: padding;
line-height:18px;
}

article blockquote {
background: #fff;
border: dashed 1px #777;
border-left: solid 2px #777;
color: #000;
margin: 0;
padding: 0 0 0 1em;
}

article ul, article ol {
padding-left: 2em;
}

article img{height:400px;width:auto;}

footer {
border-top: 1px solid #ccc;
font-size: 10pt;
margin-top: 4em;
}

@media (max-width: 768px) {

body {
padding: 0 10px 0 230px;
}

nav {
width: 230px;
}

}

@media (max-width: 480px) {

body {
padding: 64px 10px 0 10px;
}

header .banner {
display: none;
}

nav {
position: absolute;
width: 100%;
}

nav .menubar {
display: block;
}

nav .banner {
float: right;
}

nav ul {
background: #fff;
display: none;
font-size: 14pt;
margin: 0;
padding: 0 0 0 8px;
}

nav .level2 {
font-size: 16pt;
font-weight: bold;
}

nav li {
line-height: 240%;
}

.index nav ul {
display: block;
}

.index article {
display: none;
}

}
</style>
<script>
  (function (tags) {
    var i = 0, len = tags.length;

    for (; i < len; ++i) {
        document.createElement(tags[i]);
    }
  }([ 'header', 'nav', 'article', 'footer' ]));
</script>
</head>
<body>
<header>
<h1 id="-">湘小淋 注册页面修改过程</h1>

</header>
<nav>
<div class="menubar">
<a class="button">&#9776;&nbsp;索引</a>
</div>
<ul>
<li class="level2"><a href="#1">文件结构</a></li><li class="level3"><a href="#1.1">缘由</a></li><li class="level3"><a href="#1.2">文件结构</a></li><li class="level3"><a href="#1.3">图示</a></li><li class="level2"><a href="#2">分析过程</a></li><li class="level3"><a href="#2.1">原来的过程</a></li><li class="level3"><a href="#2.2">现在的过程</a></li><li class="level3"><a href="#2.3">关键</a></li><li class="level2"><a href="#3">必学的知识</a></li><li class="level3"><a href="#3.1">jquery.form.js</a></li><li class="level4"><a href="#3.1.1">官方网址</a></li><li class="level4"><a href="#3.1.2">中文翻译</a></li><li class="level4"><a href="#3.1.3">示例网址1</a></li><li class="level4"><a href="#3.1.4">学习网址2</a></li><li class="level3"><a href="#3.2">TP上传附件方法</a></li><li class="level4"><a href="#3.2.1">TP3.1上传附件方法</a></li><li class="level2"><a href="#4">用到的工具</a></li><li class="level3"><a href="#4.1">ASCII互相转换工具</a></li><li class="level2"><a href="#5">文件修改前后详细</a></li><li class="level3"><a href="#5.1">LoginAction.class.php</a></li><li class="level4"><a href="#5.1.1">reg()</a></li><li class="level3"><a href="#5.2">reg.php 注册模板</a></li><li class="level4"><a href="#5.2.1">html</a></li><li class="level4"><a href="#5.2.2">js</a></li><li class="level3"><a href="#5.3">UserModel.class.php</a></li><li class="level4"><a href="#5.3.1">checkreg()</a></li><li class="level4"><a href="#5.3.2">checkin()</a></li></ul>

</nav>
<article>
<h2 id="1">文件结构</h2>
<h3 id="1.1">缘由</h3>
<p>原来，作者用ajax的$.POST添加注册的方法。<br>由于ajax是不能添加附件的，因此必须采用 jquery.form.js 这个插件。但是逻辑关系有些复杂，因此周六一天还没能解决！<br>故此写文记录！ </p>
<h3 id="1.2">文件结构</h3>
<pre><code>└─po2o
    ├─cms
    │  └─Lib
    │      ├─Action
    │      │  ├─Index
    │      │  │      LoginAction.class.php
    │      ├─Model
    │      │      UserModel.class.php
    │              
    ├─tpl
    │  │  └─xxl
    │  │      ├─Login
    │  │      │      reg.php</code></pre>
<h3 id="1.3">图示</h3>
<p>修改前：<br><img src="images/02.png" alt=""></p>
<p>修改后：<br><img src="images/01.png" alt=""></p>

<h2 id="2">分析过程</h2>
<h3 id="2.1">原来的过程</h3>
<p>1、reg.php 是模板文件，有2个text，其中的JS采用 $.POST 方法，用 json 进行传值;<br>2、通过 reg() 把参数phone,pwd传过去，最后通过 json_encode 转化为json，回调回给 $.post。其中reg()中 用  $result = D(&#39;User&#39;)-&gt;checkreg($phone, $pwd) 的方法把手机号和密码所有值传过去 ;<br>3、把 phone,pwd 的值传过来后，再插入时间，IP等，最后通过 $condition_user 作为参数插入到数据库中。这里有一个 checkin($phone,$pwd) 是检测手机号是否存在的，是一个迷惑，做的时候一定要注意 ；  </p>
<h3 id="2.2">现在的过程</h3>
<p>1、reg.php 是模板文件，有 <strong><em>4个text</em></strong> 和 <strong><em>2个file</em></strong> ，其中的JS中不能采用 $.POST 方法传file，<strong><em>必须采用 jquery.form 插件</em></strong>进行 json 传值;<br>2、通过 reg() 把参数 phone,pwd 传过去，<strong><em>并采用ThinkPHP3.1.3的方法把 file 上传上去</em></strong>，最后通过 json_encode 转化为json，回调回给 <strong><em>jquery.form的$(this).ajaxSubmit</em></strong> 。其中reg()中 用  $result = D(&#39;User&#39;)-&gt;checkreg($phone, $pwd,<strong><em>$uname,$site,$certificate,$headphone</em></strong>) 的方法把 4个text 和 2个file 的值传过去;<br>3、把 phone, pwd,<strong><em>uname,site,certificate,headphone</em></strong> 的值传过来后，再插入时间，IP等，最后通过 $condition_user 作为参数插入到数据库中 ；  </p>
<h3 id="2.3">关键</h3>
<p>1、reg()方法中采用  <code>dump($result);exit;</code> 查看值，其中 error_code,msg,user 是学习的重点； </p>
<pre><code>array(3) {
  [&quot;error_code&quot;] =&gt; bool(false)
  [&quot;msg&quot;] =&gt; string(2) &quot;OK&quot;
  [&quot;user&quot;] =&gt; array(34) {
    [&quot;uid&quot;] =&gt; string(3) &quot;142&quot;
    [&quot;openid&quot;] =&gt; string(0) &quot;&quot;
    [&quot;web_openid&quot;] =&gt; string(0) &quot;&quot;
    [&quot;union_id&quot;] =&gt; string(0) &quot;&quot;
    [&quot;phone&quot;] =&gt; string(11) &quot;18905467855&quot;
    [&quot;pwd&quot;] =&gt; string(32) &quot;e10adc3949ba59abbe56e057f20f883e&quot;
    [&quot;nickname&quot;] =&gt; string(11) &quot;189****7855&quot;
    [&quot;sex&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;province&quot;] =&gt; string(0) &quot;&quot;
    [&quot;city&quot;] =&gt; string(0) &quot;&quot;
    [&quot;avatar&quot;] =&gt; string(0) &quot;&quot;
    [&quot;qq&quot;] =&gt; string(0) &quot;&quot;
    [&quot;add_time&quot;] =&gt; string(10) &quot;1462772022&quot;
    [&quot;add_ip&quot;] =&gt; string(10) &quot;2130706433&quot;
    [&quot;last_time&quot;] =&gt; string(10) &quot;1462772022&quot;
    [&quot;last_ip&quot;] =&gt; string(10) &quot;2130706433&quot;
    [&quot;last_weixin_time&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;score_count&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;now_money&quot;] =&gt; string(4) &quot;0.00&quot;
    [&quot;is_check_phone&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;is_follow&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;status&quot;] =&gt; string(1) &quot;1&quot;
    [&quot;truename&quot;] =&gt; string(0) &quot;&quot;
    [&quot;birthday&quot;] =&gt; string(10) &quot;0000-00-00&quot;
    [&quot;occupation&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;message&quot;] =&gt; string(0) &quot;&quot;
    [&quot;weidian_sessid&quot;] =&gt; string(0) &quot;&quot;
    [&quot;email&quot;] =&gt; string(0) &quot;&quot;
    [&quot;importid&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;level&quot;] =&gt; string(1) &quot;0&quot;
    [&quot;uname&quot;] =&gt; string(7) &quot;1235787&quot;
    [&quot;site&quot;] =&gt; string(7) &quot;4545454&quot;
    [&quot;certificate&quot;] =&gt; string(26) &quot;./upload/57302136ce9af.jpg&quot;
    [&quot;headphone&quot;] =&gt; string(26) &quot;./upload/57302136d4b9f.jpg&quot;
  }
}</code></pre>
<p>2、checkreg()方法中采用  <code>dump($data_user);exit;</code> 查看插入数据库值；  </p>
<pre><code>array(12) {
  [&quot;phone&quot;] =&gt; string(11) &quot;18903467858&quot;
  [&quot;pwd&quot;] =&gt; string(32) &quot;e10adc3949ba59abbe56e057f20f883e&quot;
  [&quot;status&quot;] =&gt; int(1)
  [&quot;nickname&quot;] =&gt; string(11) &quot;189****7858&quot;
  [&quot;last_time&quot;] =&gt; int(1462762404)
  [&quot;add_time&quot;] =&gt; int(1462762404)
  [&quot;last_ip&quot;] =&gt; string(10) &quot;2130706433&quot;
  [&quot;add_ip&quot;] =&gt; string(10) &quot;2130706433&quot;
  [&quot;uname&quot;] =&gt; string(6) &quot;222222&quot;
  [&quot;site&quot;] =&gt; string(7) &quot;1312321&quot;
  [&quot;certificate&quot;] =&gt; string(26) &quot;./upload/572ffba498f96.jpg&quot;
  [&quot;headphone&quot;] =&gt; string(26) &quot;./upload/572ffba49f1f8.jpg&quot;
}</code></pre>
<p>3、TP3.1.3上传附件的方法；<br>4、jquery.form.js 参数及回调的方法；<br>5、form 采用 action 的方法进行调试的方法；<br>6、出现下边这个json原因，是因为正确，前台没有收到到json，把调试过程的前台的 form表单 的 action 方法改为 jquery.form 的 json 方步即可！。  </p>
<pre><code>{&quot;error_code&quot;:false,&quot;msg&quot;:&quot;OK&quot;,&quot;user&quot;:{&quot;uid&quot;:&quot;144&quot;,&quot;openid&quot;:&quot;&quot;,&quot;web_openid&quot;:&quot;&quot;,&quot;union_id&quot;:&quot;&quot;,&quot;phone&quot;:&quot;18903467858&quot;,&quot;pwd&quot;:&quot;e10adc3949ba59abbe56e057f20f883e&quot;,&quot;nickname&quot;:&quot;189****7858&quot;,&quot;sex&quot;:&quot;0&quot;,&quot;province&quot;:&quot;&quot;,&quot;city&quot;:&quot;&quot;,&quot;avatar&quot;:&quot;&quot;,&quot;qq&quot;:&quot;&quot;,&quot;add_time&quot;:&quot;1462772343&quot;,&quot;add_ip&quot;:&quot;2130706433&quot;,&quot;last_time&quot;:&quot;1462772343&quot;,&quot;last_ip&quot;:&quot;2130706433&quot;,&quot;last_weixin_time&quot;:&quot;0&quot;,&quot;score_count&quot;:&quot;0&quot;,&quot;now_money&quot;:&quot;0.00&quot;,&quot;is_check_phone&quot;:&quot;0&quot;,&quot;is_follow&quot;:&quot;0&quot;,&quot;status&quot;:&quot;1&quot;,&quot;truename&quot;:&quot;&quot;,&quot;birthday&quot;:&quot;0000-00-00&quot;,&quot;occupation&quot;:&quot;0&quot;,&quot;message&quot;:&quot;&quot;,&quot;weidian_sessid&quot;:&quot;&quot;,&quot;email&quot;:&quot;&quot;,&quot;importid&quot;:&quot;0&quot;,&quot;level&quot;:&quot;0&quot;,&quot;uname&quot;:&quot;1235787&quot;,&quot;site&quot;:&quot;4545454&quot;,&quot;certificate&quot;:&quot;.\/upload\/573022770d62f.jpg&quot;,&quot;headphone&quot;:&quot;.\/upload\/5730227714ab3.jpg&quot;}}</code></pre>

<h2 id="3">必学的知识</h2>
<h3 id="3.1">jquery.form.js</h3>
<h4 id="3.1.1">官方网址</h4>
<p>网址：<a href="https://github.com/malsup/form">https://github.com/malsup/form</a></p>
<h4 id="3.1.2">中文翻译</h4>
<p>网址1： <a href="http://www.vaikan.com/docs/jquery.form.plugin/jquery.form.plugin.html">http://www.vaikan.com/docs/jquery.form.plugin/jquery.form.plugin.html</a></p>
<h4 id="3.1.3">示例网址1</h4>
<p><a href="http://www.jb51.net/article/48728.htm">http://www.jb51.net/article/48728.htm</a>  </p>
<p>ajaxSubmit(obj)方法是jQuery的一个插件jquery.form.js里面的方法，所以使用此方法需要先引入这个插件。如下所示：  </p>
<pre><code>&lt;script src=&quot;http://code.jquery.com/jquery-1.11.0.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;http://malsup.github.io/jquery.form.js&quot;&gt;&lt;/script&gt;</code></pre>
<p>那么，如何通过ajaxSubmit(obj)提交数据呢？首先我们需要一个form：    </p>
<p>HTML  </p>
<pre><code>&lt;form&gt;
    标题：&lt;input type=&quot;text&quot; name=&quot;title&quot; /&gt;&lt;br /&gt;
    内容：&lt;textarea name=&quot;content&quot;&gt;&lt;textarea/&gt;&lt;br /&gt;
    &lt;button&gt;提交&lt;/button&gt;
&lt;/form&gt;</code></pre>
<p>上面是一个需要提交内容的form，通常情况下，我们直接通过form提交的话， 提交后当前页面跳转到form的action所指向的页面。然而，很多时候我们比不希望提交表单后页面跳转，那么，我们就可以使用ajaxSubmit(obj)来提交数据。使用方法如下所示：    </p>
<pre><code>$(&#39;button&#39;).on(&#39;click&#39;, function() {

    $(&#39;form&#39;).on(&#39;submit&#39;, function() {
        var title = $(&#39;inpur[name=title]&#39;).val(),
            content = $(&#39;textarea&#39;).val();

        $(this).ajaxSubmit({
            type: &#39;post&#39;, // 提交方式 get/post
            url: &#39;your url&#39;, // 需要提交的 url
            data: {
                &#39;title&#39;: title,
                &#39;content&#39;: content
            },
            success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
                // 此处可对 data 作相关处理
                alert(&#39;提交成功！&#39;);
            }
            $(this).resetForm(); // 提交后重置表单
        });
        return false; // 阻止表单自动提交事件
    });
});</code></pre>
<h4 id="3.1.4">学习网址2</h4>
<p><a href="http://jingyan.baidu.com/article/0a52e3f41e8c04bf62ed72ec.html">http://jingyan.baidu.com/article/0a52e3f41e8c04bf62ed72ec.html</a>  </p>
<p>现在大家在在表单提交的时候都不流行中间页面做跳转（比如发布成功的提示页面），或者说这样做会降低用户体验。所以一般都是采用ajax来提交，能看到这个页面的朋友，想必对ajax提交表单已经是很熟悉了。  </p>
<p>如果是表单的值是修改密码这种，表单的值比较少，还好，我们可以通过  </p>
<p>$.post(url,{password:password},function(data){})  </p>
<p>这样来做处理，如果一个表单有20个input需要输入，而且还有很多input表单的name名是二维数组，例如<input name="info[name]" >这样的。我们应该怎么办呢？  </p>
<p>如果使用jquery，知道jquery提供了一个$(&quot;form&quot;).serializeArray()的方法，可以用在这里解决。但是还需要自己来做一些处理。  </p>
<p>如果使用jquery.form.js来做提交的话，就可以省略这几步啦，不管表单多复杂，它都帮我们封装好发送的机制了。  </p>
<p>让我们在发送表单的时候感觉就像是直接发送post一样！  </p>
<p>比如这边发送的是<input name="info[name]">的值  </p>
<p>在php端，则可以直接使用$_POST[&#39;info&#39;][&#39;name&#39;]来获取了。  </p>
<h3 id="3.2">TP上传附件方法</h3>
<h4 id="3.2.1">TP3.1上传附件方法</h4>
<pre><code>//上传图片到uploads文件夹 start
import(&#39;ORG.Net.UploadFile&#39;);
$upload = new UploadFile();// 实例化上传类
$upload-&gt;maxSize  = 3145728 ;// 设置附件上传大小
$upload-&gt;allowExts = array(&#39;jpg&#39;, &#39;gif&#39;, &#39;png&#39;, &#39;jpeg&#39;);// 设置附件上传类型
$upload-&gt;savePath =  &#39;./upload/&#39;;// 设置附件上传目录
if(!$upload-&gt;upload()) {// 上传错误提示错误信息
    $this-&gt;error($upload-&gt;getErrorMsg());
}else {  // 上传成功 获取上传文件信息
    $info = $upload-&gt;getUploadFileInfo();
}
//上传图片到uploads文件夹 end</code></pre>
<p>更详细的请看 《ThinkPHP3.1.2 和 ThinkPHP3.2.3 “form上传附件及插入数据库”和“Ajax上传附件及插入数据库”的方法及区别》。 </p>

<h2 id="4">用到的工具</h2>
<h3 id="4.1">ASCII互相转换工具</h3>
<p>网址：<a href="http://www.atool.org/chinese2unicode.php">http://www.atool.org/chinese2unicode.php</a></p>

<h2 id="5">文件修改前后详细</h2>
<p>采用 pigcms 制作，在5月6日下午由郝飞添加注册附件。  </p>
<h3 id="5.1">LoginAction.class.php</h3>
<p>位置：D:\www\www_company\po2o\cms\Lib\Action\Index\LoginAction.class.php</p>
<h4 id="5.1.1">reg()</h4>
<p>原注册跳转：</p>
<pre><code>public function reg() {
    if (IS_POST) {
        $phone = isset($_POST[&#39;phone&#39;]) ? $_POST[&#39;phone&#39;] : &#39;&#39;;
        $pwd = isset($_POST[&#39;pwd&#39;]) ? $_POST[&#39;pwd&#39;] : &#39;&#39;;

        $result = D(&#39;User&#39;)-&gt;checkreg($phone, $pwd);
        if (!empty($result[&#39;user&#39;])) {
            session(&#39;user&#39;, $result[&#39;user&#39;]);
        }
        exit(json_encode($result));
    } else {
        $pigcms_assign[&#39;referer&#39;] = !empty($_GET[&#39;referer&#39;]) ? strip_tags(htmlspecialchars_decode($_GET[&#39;referer&#39;])) : (!empty($_SERVER[&#39;HTTP_REFERER&#39;]) ? strip_tags($_SERVER[&#39;HTTP_REFERER&#39;]) : U(&#39;Index/Index/index&#39;));
        $pigcms_assign[&#39;url_referer&#39;] = urlencode($pigcms_assign[&#39;referer&#39;]);
        $this-&gt;assign($pigcms_assign);

        $this-&gt;display();
    }
}</code></pre>
<p>修改后注册跳转：</p>
<pre><code>public function reg2() {
    if (IS_POST) {

        //上传图片到uploads文件夹 start
        import(&#39;ORG.Net.UploadFile&#39;);
        $upload = new UploadFile();// 实例化上传类
        $upload-&gt;maxSize  = 3145728 ;// 设置附件上传大小
        $upload-&gt;allowExts = array(&#39;jpg&#39;, &#39;gif&#39;, &#39;png&#39;, &#39;jpeg&#39;);// 设置附件上传类型
        $upload-&gt;savePath =  &#39;./upload/&#39;;// 设置附件上传目录
        if(!$upload-&gt;upload()) {// 上传错误提示错误信息
            $this-&gt;error($upload-&gt;getErrorMsg());
        }else {  // 上传成功 获取上传文件信息
            $info = $upload-&gt;getUploadFileInfo();
        }
        //上传图片到uploads文件夹 end

        $phone = isset($_POST[&#39;phone&#39;]) ? $_POST[&#39;phone&#39;] : &#39;&#39;;
        $pwd = isset($_POST[&#39;pwd&#39;]) ? $_POST[&#39;pwd&#39;] : &#39;&#39;;

        $uname = isset($_POST[&#39;uname&#39;]) ? $_POST[&#39;uname&#39;] : &#39;&#39;;
        $site = isset($_POST[&#39;site&#39;]) ? $_POST[&#39;site&#39;] : &#39;&#39;;
        $certificate = $info[0][savepath].$info[0][savename];
        $headphone = $info[1][savepath].$info[1][savename];

        $result = D(&#39;User&#39;)-&gt;checkreg2($phone, $pwd,$uname,$site,$certificate,$headphone);

        if (!empty($result[&#39;user&#39;])) {
            session(&#39;user&#39;, $result[&#39;user&#39;]);
        }
        exit(json_encode($result));

    } else {
        $pigcms_assign[&#39;referer&#39;] = !empty($_GET[&#39;referer&#39;]) ? strip_tags(htmlspecialchars_decode($_GET[&#39;referer&#39;])) : (!empty($_SERVER[&#39;HTTP_REFERER&#39;]) ? strip_tags($_SERVER[&#39;HTTP_REFERER&#39;]) : U(&#39;Index/Index/index&#39;));
        $pigcms_assign[&#39;url_referer&#39;] = urlencode($pigcms_assign[&#39;referer&#39;]);
        $this-&gt;assign($pigcms_assign);

        $this-&gt;display();
    }
}</code></pre>
<h3 id="5.2">reg.php 注册模板</h3>
<h4 id="5.2.1">html</h4>
<p>位置：\po2o\tpl\Index\xxl\Login\reg.php</p>
<pre><code>&lt;form id=&quot;J-login-form&quot; method=&quot;post&quot; class=&quot;form form--stack J-wwwtracker-form&quot; &gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;text&quot; id=&quot;login-phone&quot; class=&quot;f-text&quot; name=&quot;phone&quot; placeholder=&quot;手机号&quot; value=&quot;18903467858&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot; &gt;
        &lt;i class=&quot;icon icon-password&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;password&quot; id=&quot;login-password&quot; class=&quot;f-text&quot; name=&quot;pwd&quot; placeholder=&quot;密码&quot; value=&quot;123456&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot; &gt;
        &lt;i class=&quot;icon icon-password&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;password&quot; id=&quot;login-repassword&quot; class=&quot;f-text&quot; name=&quot;repwd&quot; placeholder=&quot;再输入一次密码&quot; value=&quot;123456&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--ops&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;fingerprint&quot; class=&quot;J-fingerprint&quot;/&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;origin&quot; value=&quot;account-login&quot;/&gt;
        &lt;input type=&quot;submit&quot; class=&quot;btn&quot; id=&quot;commit&quot; value=&quot;注册&quot;/&gt;
    &lt;/div&gt;
&lt;/form&gt;</code></pre>
<p>调试中：  </p>
<pre><code>&lt;form id=&quot;J-login-form&quot; method=&quot;post&quot; action=&quot;{pigcms{:U(&#39;Login/reg2&#39;,array(&#39;referer&#39;=&gt;urlencode($referer)))}&quot; class=&quot;form form--stack J-wwwtracker-form&quot; enctype=&quot;multipart/form-data&quot;&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;text&quot; id=&quot;login-phone&quot; class=&quot;f-text&quot; name=&quot;phone&quot; placeholder=&quot;手机号&quot; value=&quot;18903467858&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot; &gt;
        &lt;i class=&quot;icon icon-password&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;password&quot; id=&quot;login-password&quot; class=&quot;f-text&quot; name=&quot;pwd&quot; placeholder=&quot;密码&quot; value=&quot;123456&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot; &gt;
        &lt;i class=&quot;icon icon-password&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;password&quot; id=&quot;login-repassword&quot; class=&quot;f-text&quot; name=&quot;repwd&quot; placeholder=&quot;再输入一次密码&quot; value=&quot;123456&quot;/&gt;
    &lt;/div&gt;
    &lt;!--新增代码 start--&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;text&quot; id=&quot;login-uname&quot; class=&quot;f-text&quot; name=&quot;uname&quot; placeholder=&quot;姓名&quot; value=&quot;222222&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;text&quot; id=&quot;login-site&quot; class=&quot;f-text&quot; name=&quot;site&quot; placeholder=&quot;地址&quot; value=&quot;1312321&quot;/&gt;
    &lt;/div&gt;
    &lt;h3&gt;营业执照&lt;/h3&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;file&quot; id=&quot;login-certificate&quot; class=&quot;f-text&quot; name=&quot;certificate[]&quot; placeholder=&quot;营业执照&quot;/&gt;
    &lt;/div&gt;
    &lt;h3&gt;门头照片&lt;/h3&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;file&quot; id=&quot;login-headphone&quot; class=&quot;f-text&quot; name=&quot;certificate[]&quot; placeholder=&quot;门头照片&quot;/&gt;
    &lt;/div&gt;
    &lt;!--新增代码 end--&gt;
    &lt;div class=&quot;form-field form-field--ops&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;fingerprint&quot; class=&quot;J-fingerprint&quot;/&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;origin&quot; value=&quot;account-login&quot;/&gt;
        &lt;input type=&quot;submit&quot; class=&quot;btn&quot; id=&quot;commit&quot; value=&quot;注册&quot;/&gt;
    &lt;/div&gt;
&lt;/form&gt;</code></pre>
<p>修改后：</p>
<pre><code>&lt;script src=&quot;//cdn.bootcss.com/jquery.form/3.51/jquery.form.min.js&quot;&gt;&lt;/script&gt;
&lt;form id=&quot;J-login-form&quot; method=&quot;post&quot;  class=&quot;form form--stack J-wwwtracker-form&quot; &gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;text&quot; id=&quot;login-phone&quot; class=&quot;f-text&quot; name=&quot;phone&quot; placeholder=&quot;手机号&quot; value=&quot;&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot; &gt;
        &lt;i class=&quot;icon icon-password&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;password&quot; id=&quot;login-password&quot; class=&quot;f-text&quot; name=&quot;pwd&quot; placeholder=&quot;密码&quot; value=&quot;&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot; &gt;
        &lt;i class=&quot;icon icon-password&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;password&quot; id=&quot;login-repassword&quot; class=&quot;f-text&quot; name=&quot;repwd&quot; placeholder=&quot;再输入一次密码&quot; value=&quot;&quot;/&gt;
    &lt;/div&gt;
    &lt;!--新增代码 start--&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;text&quot; id=&quot;login-uname&quot; class=&quot;f-text&quot; name=&quot;uname&quot; placeholder=&quot;姓名&quot; value=&quot;&quot;/&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;text&quot; id=&quot;login-site&quot; class=&quot;f-text&quot; name=&quot;site&quot; placeholder=&quot;地址&quot; value=&quot;&quot;/&gt;
    &lt;/div&gt;
    &lt;h3&gt;营业执照&lt;/h3&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;file&quot; id=&quot;login-certificate&quot; class=&quot;f-text&quot; name=&quot;certificate[]&quot; placeholder=&quot;营业执照&quot;/&gt;
    &lt;/div&gt;
    &lt;h3&gt;门头照片&lt;/h3&gt;
    &lt;div class=&quot;form-field form-field--icon&quot;&gt;
        &lt;i class=&quot;icon icon-user&quot;&gt;&lt;/i&gt;
        &lt;input type=&quot;file&quot; id=&quot;login-headphone&quot; class=&quot;f-text&quot; name=&quot;certificate[]&quot; placeholder=&quot;门头照片&quot;/&gt;
    &lt;/div&gt;
    &lt;!--新增代码 end--&gt;
    &lt;div class=&quot;form-field form-field--ops&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;fingerprint&quot; class=&quot;J-fingerprint&quot;/&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;origin&quot; value=&quot;account-login&quot;/&gt;
        &lt;input type=&quot;submit&quot; class=&quot;btn&quot; id=&quot;commit&quot; value=&quot;注册&quot;/&gt;
    &lt;/div&gt;
&lt;/form&gt;</code></pre>
<h4 id="5.2.2">js</h4>
<p>原注册 JS</p>
<pre><code>$(&quot;#J-login-form&quot;).submit(function(){
    $(&#39;.validate-info&#39;).css(&#39;visibility&#39;,&#39;hidden&#39;);
    $(&#39;#commit&#39;).val(&#39;注册中...&#39;).prop(&#39;disabled&#39;,true);
    $(&quot;#login-phone&quot;).val($.trim($(&quot;#login-phone&quot;).val()));
    $(&quot;#login-password&quot;).val($.trim($(&quot;#login-password&quot;).val()));
    $(&quot;#login-repassword&quot;).val($.trim($(&quot;#login-repassword&quot;).val()));
    $(&quot;#login-uname&quot;).val($.trim($(&quot;#login-uname&quot;).val()));

    var phone = $(&quot;#login-phone&quot;).val();
    var pwd = $(&quot;#login-password&quot;).val();
    var repwd = $(&quot;#login-repassword&quot;).val();
    var uname = $(&quot;#login-uname&quot;).val();

    if(phone == &#39;&#39; || phone == null){
        error_tips(&#39;手机号不能为空&#39;,&#39;login-phone&#39;);
        return false;
    }
    if(!/^[0-9]{11}$/.test(phone)){
        error_tips(&#39;请输入11位数字的手机号码&#39;,&#39;login-phone&#39;);
        return false;
    }
    if(pwd == &#39;&#39; || pwd == null){
        error_tips(&#39;密码不能为空&#39;,&#39;login-password&#39;);
        return false;
    }
    if(pwd != repwd){
        error_tips(&#39;两次密码输入不一致&#39;,&#39;login-repassword&#39;);
        return false;
    }
    $.post(&quot;{pigcms{:U(&#39;Index/Login/reg&#39;)}&quot;, {&#39;phone&#39;:phone,&#39;pwd&#39;:pwd,&#39;uname&#39;:uname,&#39;site&#39;:site }, function(data){
        if(data.error_code){
            $(&quot;#commit&quot;).val(&#39;注册&#39;).prop(&#39;disabled&#39;,false);
            $(&#39;.validate-info&#39;).html(&#39;&lt;i class=&quot;tip-status tip-status--opinfo&quot;&gt;&lt;/i&gt;&#39;+data.msg).css(&#39;visibility&#39;,&#39;visible&#39;);
            return false;
        }else if(data.user){
            $(&#39;.validate-info&#39;).html(&#39;&lt;i class=&quot;tip-status tip-status--success&quot;&gt;&lt;/i&gt;注册且登录成功！正在跳转.&#39;).css(&#39;visibility&#39;,&#39;visible&#39;);
            setTimeout(&quot;location.href=&#39;{pigcms{$referer}&#39;&quot;, 1000);
        }else{
            $(&#39;.validate-info&#39;).html(&#39;&lt;i class=&quot;tip-status tip-status--success&quot;&gt;&lt;/i&gt;注册成功！正在跳转登录页.&#39;).css(&#39;visibility&#39;,&#39;visible&#39;);
            setTimeout(&quot;location.href=&#39;{pigcms{:U(&#39;Login/index&#39;,array(&#39;referer&#39;=&gt;urlencode($referer)))}&#39;&quot;, 1000);
        }
    }, &#39;json&#39;);

    return false;
});</code></pre>
<p>修改后注册JS：  </p>
<pre><code>$(&quot;#J-login-form&quot;).submit(function(){
    $(&#39;.validate-info&#39;).css(&#39;visibility&#39;,&#39;hidden&#39;);
    $(&#39;#commit&#39;).val(&#39;注册中...&#39;).prop(&#39;disabled&#39;,true);
    $(&quot;#login-phone&quot;).val($.trim($(&quot;#login-phone&quot;).val()));
    $(&quot;#login-password&quot;).val($.trim($(&quot;#login-password&quot;).val()));
    $(&quot;#login-repassword&quot;).val($.trim($(&quot;#login-repassword&quot;).val()));
    $(&quot;#login-uname&quot;).val($.trim($(&quot;#login-uname&quot;).val()));
    $(&quot;#login-site&quot;).val($.trim($(&quot;#login-site&quot;).val()));

    var phone = $(&quot;#login-phone&quot;).val();
    var pwd = $(&quot;#login-password&quot;).val();
    var repwd = $(&quot;#login-repassword&quot;).val();
    var uname = $(&quot;#login-uname&quot;).val();
    var site = $(&quot;#login-site&quot;).val();
    var certificate = $(&quot;#login-certificate&quot;).val();
    var headphone = $(&quot;#login-headphone&quot;).val();
    if(phone == &#39;&#39; || phone == null){
        error_tips(&#39;手机号不能为空&#39;,&#39;login-phone&#39;);
        return false;
    }
    if(!/^[0-9]{11}$/.test(phone)){
        error_tips(&#39;请输入11位数字的手机号码&#39;,&#39;login-phone&#39;);
        return false;
    }
    if(pwd == &#39;&#39; || pwd == null){
        error_tips(&#39;密码不能为空&#39;,&#39;login-password&#39;);
        return false;
    }
    if(pwd != repwd){
        error_tips(&#39;两次密码输入不一致&#39;,&#39;login-repassword&#39;);
        return false;
    }

    $(this).ajaxSubmit({
        type: &quot;post&quot;, // 提交方式 get/post
        url: &quot;{pigcms{:U(&#39;Index/Login/reg2&#39;)}&quot;, // 需要提交的 url
        data: {
            &#39;phone&#39;:phone,
            &#39;pwd&#39;:pwd,
            &#39;uname&#39;:uname,
            &#39;site&#39;:site,
            &#39;certificate&#39;:certificate,
            &#39;headphone&#39;:headphone,
        },
        dataType:  &quot;json&quot;,
        success: function(data) {
            //alert(&#39;提交成功！&#39;);
            console.log(data);
            if(data.error_code){
                $(&quot;#commit&quot;).val(&#39;注册&#39;).prop(&#39;disabled&#39;,false);
                $(&#39;.validate-info&#39;).html(&#39;&lt;i class=&quot;tip-status tip-status--opinfo&quot;&gt;&lt;/i&gt;&#39;+data.msg).css(&#39;visibility&#39;,&#39;visible&#39;);
                return false;
            }else if(data.user){
                $(&#39;.validate-info&#39;).html(&#39;&lt;i class=&quot;tip-status tip-status--success&quot;&gt;&lt;/i&gt;注册且登录成功！正在跳转.&#39;).css(&#39;visibility&#39;,&#39;visible&#39;);
                setTimeout(&quot;location.href=&#39;{pigcms{$referer}&#39;&quot;, 1000);
            }else{
                $(&#39;.validate-info&#39;).html(&#39;&lt;i class=&quot;tip-status tip-status--success&quot;&gt;&lt;/i&gt;注册成功！正在跳转登录页.&#39;).css(&#39;visibility&#39;,&#39;visible&#39;);
                setTimeout(&quot;location.href=&#39;{pigcms{:U(&#39;Login/index&#39;,array(&#39;referer&#39;=&gt;urlencode($referer)))}&#39;&quot;, 1000);
            }
        },
        error:function(xhr){
            console.log(&quot;error&quot;);
        }
        //$(this).resetForm(); // 提交后重置表单
    });
    return false;
});</code></pre>
<h3 id="5.3">UserModel.class.php</h3>
<h4 id="5.3.1">checkreg()</h4>
<p>位置： D:\www\www_company\po2o\cms\Lib\Model\UserModel.class.php</p>
<p>修改前：  </p>
<pre><code>public function checkreg($phone,$pwd){
    if (empty($phone)) {
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;手机号不能为空&#39;);
    }
    if (empty($pwd)) {
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;密码不能为空&#39;);
    }

    if(!preg_match(&#39;/^[0-9]{11}$/&#39;,$phone)){
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;请输入有效的手机号&#39;);
    }

    $condition_user[&#39;phone&#39;] = $phone;
    if($this-&gt;field(&#39;`uid`&#39;)-&gt;where($condition_user)-&gt;find()){
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;手机号已存在&#39;);
    }

    $data_user[&#39;phone&#39;] = $phone;
    $data_user[&#39;pwd&#39;] = md5($pwd);
    $data_user[&#39;status&#39;] = 1;
    $register_give_money_condition = C(&#39;config.register_give_money_condition&#39;);
    if ($register_give_money_condition == 1 || $register_give_money_condition == 3) {
        $data_user[&#39;now_money&#39;] = C(&#39;config.register_give_money&#39;);
    }
    $data_user[&#39;nickname&#39;] = substr($phone,0,3).&#39;****&#39;.substr($phone,7);

    $data_user[&#39;add_time&#39;] = $data_user[&#39;last_time&#39;] = $_SERVER[&#39;REQUEST_TIME&#39;];
    $data_user[&#39;add_ip&#39;] = $data_user[&#39;last_ip&#39;] = get_client_ip(1);

    if($this-&gt;data($data_user)-&gt;add()){
        $return = $this-&gt;checkin($phone,$pwd);

        if(empty($result[&#39;error_code&#39;])){
            return $return;
        }else{
            return array(&#39;error_code&#39; =&gt;false,&#39;msg&#39; =&gt;&#39;OK&#39;);
        }
    }else{
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;注册失败！请重试。&#39;);
    }
}</code></pre>
<p>修改后：</p>
<pre><code>/*帐号密码注册*/
public function checkreg2($phone, $pwd,$uname,$site,$certificate,$headphone){
    if (empty($phone)) {
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;手机号不能为空&#39;);
    }
    if (empty($pwd)) {
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;密码不能为空&#39;);
    }

    if(!preg_match(&#39;/^[0-9]{11}$/&#39;,$phone)){
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;请输入有效的手机号&#39;);
    }

    $condition_user[&#39;phone&#39;] = $phone;

    if($this-&gt;field(&#39;`uid`&#39;)-&gt;where($condition_user)-&gt;find()){
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;手机号已存在&#39;);
    }
    $data_user[&#39;phone&#39;] = $phone;
    $data_user[&#39;pwd&#39;] = md5($pwd);
    $data_user[&#39;status&#39;] = 1;
    //now_money start
    $register_give_money_condition = C(&#39;config.register_give_money_condition&#39;);

    if ($register_give_money_condition == 1 || $register_give_money_condition == 3) {
        $data_user[&#39;now_money&#39;] = C(&#39;config.register_give_money&#39;);
    }
    //now_money start
    $register_give_money_condition = C(&#39;config.register_give_money_condition&#39;);

    if ($register_give_money_condition == 1 || $register_give_money_condition == 3) {
        $data_user[&#39;now_money&#39;] = C(&#39;config.register_give_money&#39;);
    }
    //now_money end
    $data_user[&#39;nickname&#39;] = substr($phone,0,3).&#39;****&#39;.substr($phone,7);
    $data_user[&#39;add_time&#39;] = $data_user[&#39;last_time&#39;] = $_SERVER[&#39;REQUEST_TIME&#39;];
    $data_user[&#39;add_ip&#39;] = $data_user[&#39;last_ip&#39;] = get_client_ip(1);
    $data_user[&#39;uname&#39;] = $uname;
    $data_user[&#39;site&#39;] = $site;
    $data_user[&#39;certificate&#39;]  = $certificate;
    $data_user[&#39;headphone&#39;]  = $headphone;

    //dump($data_user);exit;


    if($this-&gt;data($data_user)-&gt;add()){
        $return = $this-&gt;checkin($phone,$pwd);
        if(empty($result[&#39;error_code&#39;])){
            return $return;
        }else{
            return array(&#39;error_code&#39; =&gt;false,&#39;msg&#39; =&gt;&#39;OK&#39;);
        }
    }else{
        return array(&#39;error_code&#39; =&gt; true, &#39;msg&#39; =&gt; &#39;注册失败！请重试。&#39;);
    }
}</code></pre>
<h4 id="5.3.2">checkin()</h4>
<pre><code>与系统无关，可不修改！也可修改！</code></pre>

</article>
<footer>
<p>© 2016 龙之翼网络科技</p>

</footer>
</body>
</html>
